<template>
  <!-- 会员管理 -->
  <view class="member-list-container">
    <List ref="list" :fetchData="fetchData" :page-size="20">
      <MemberItem v-for="(item, index) in list" :key="index" :data="item" @click.native="gotoLog(item)" />
    </List>
  </view>
</template>

<script>
import { mapActions } from "vuex";
import List from "../../components/public/List/index.vue";
import MemberItem from "./components/MemberItem.vue";
export default {
  components: {
    List,
    MemberItem
  },
  data() {
    return {
      searchParams: {},
      list: [],
      finished: false,
      loading: true,
      total: null
    };
  },
  onPullDownRefresh() {
    this.$refs.list.reset();
  },
  methods: {
    ...mapActions({
      getMembers: "getMembers"
    }),
    async fetchData(params, refreshing) {
      let Search = {};
      for (let key in this.searchParams) {
        if (this.searchParams[key] || this.searchParams[key] === 0)
          Search[key] = this.searchParams[key];
      }
      let query = Object.assign({}, params, Search);
      try {
        let res = await this.getMembers(query);
        if (refreshing) this.list = [];
        this.list = this.list.concat(res.rows);
        return res;
      } catch (error) {
        return Promise.reject();
      }
    },
    gotoLog(item) {
      this.$goto("financeLogs", { userId: item.userId });
    }
  }
};
</script>

<style lang="scss">
.member-list-container {
  padding-top: 20rpx;
  height: 100%;
}
</style>
